********************************************************************************
* Leipziger, L, Aarslew, L, & M. Christensen
* Replication Code for "Do Group-Based Inequalities Feel More Unjust?"
* POQ, 2026
* This code: Figure SM21: Dictionary approch - attributions to personal merit or effort 
********************************************************************************
*********************************************************************************
clear all
frame rename default data

** Marginal effects (India): 
import excel "data\dictionary_IN.xlsx", sheet("Sheet 1") firstrow clear
encode D, generate(treat)
qui reg effort_dum i.treat , rob				
margins, at(treat=(1(1)3))
mat A = r(table)
est store india // for tables
estadd scalar ajr2 = e(r2_a)

** Marginal effects (South Africa)
import excel "data\dictionary_ZA.xlsx", sheet("Sheet 1") firstrow clear
encode D, generate(treat)
qui reg effort_dum i.treat , rob				
margins, at(treat=(1(1)3))
mat B = r(table)
est store za // for tables
estadd scalar ajr2 = e(r2_a)


** Marginal effects (USA)
import excel "data\dictionary_US.xlsx", sheet("Sheet 1") firstrow clear
encode D, generate(treat)
drop if treat==4 | treat==5
qui reg effort_dum i.treat , rob					// Intragroup inequality treatments dropped 
margins, at(treat=(1(1)3))
mat C = r(table)
est store us // for tables
estadd scalar ajr2 = e(r2_a)

lab define treat_lb 1 "Baseline" 2 "\forceindent Intergroup ineq." 3 "\forceindent Interpersonal ineq."
lab values treat treat_lb


* Matrix 
mat D = 1,0.9,A[1,1],A[5,1],A[6,1]\			/// 
		2,1.0,A[1,2],A[5,2],A[6,2]\			///
		3,1.1,A[1,3],A[5,3],A[6,3]\			///
		1,1.9,B[1,1],B[5,1],B[6,1]\			/// 
		2,2.0,B[1,2],B[5,2],B[6,2]\			///
		3,2.1,B[1,3],B[5,3],B[6,3]\			///
		1,2.9,C[1,1],C[5,1],C[6,1]\			/// 
		2,3.0,C[1,2],C[5,2],C[6,2]\			///
		3,3.1,C[1,3],C[5,3],C[6,3]			

		
mat list D	


frame create plot1
cwf plot1		
svmat D
rename D1 treatment						// 1 = Interpersonal, 2 = Intergroup
rename D2 Xpos							// Position on X-axis
rename D3 b								// Parameter estimate (Marginal effect)
rename D4 ll							// lower confidence level
rename D5 ul							// upper confidence level


* Plot: 
tw ///
	(rspike ll ul Xpos if treatment == 1, lc(gs10)) ///
	(rspike ll ul Xpos if treatment == 2, lc(black)) ///
	(rspike ll ul Xpos if treatment == 3, lc(black)) ///
	(scatter b Xpos if treatment == 1, msym(D) mc(gs10) msize(med)) ///
	(scatter b Xpos if treatment == 2, msym(O) mc(black) msize(med)) ///
	(scatter b Xpos if treatment == 3, msym(O) mc(black) mfcolor(white) msize(med)) ///
	, yscale(range(-0.22 0.22) extend lc(none)) ytit("% Mentioning a Word" "related to Interpersonal Ineq.", size(medsmall)) ///
	yline(0) ylab(-0.2 -0.1 0 0.1 0.2, labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	xscale(range(.5 3.5) extend) xtit("Country", size(medsmall)) ///
	xlab(1 "India" 2 "South Africa" 3 "United States", labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	legend(pos(7) ring(0) order(4 "Control Group" 5 "Intergroup Inequality" 6 "Interpersonal Inequality") size(vsmall)) ///
	plotregion(lcolor(black) lwidth(medium)) ///
	scale(1.3) graphregion(m(small)) ///
	tit("{bf:(B)} Interpersonal ineq. dictionary", pos(11) justification(left) size(med)) ///
	name(dist_fair, replace)
graph display, xsize(12) ysize(8) 

graph export "output/figure_SM21.pdf", as(pdf) replace
	
	